/*
 * Copyright (C) 2018 Logos Technology Ltd.
 */

package com.logos.common.keepalive;

/**
 * Created by llx on 2018/11/9.
 */

import android.os.Bundle;
import android.view.KeyEvent;
import android.view.WindowManager;
import android.widget.TextView;

import androidx.annotation.Nullable;
import androidx.appcompat.app.AppCompatActivity;

import com.logos.common.R;
import com.logos.common.keepalive.widget.ShimmerTextView;
import com.logos.common.keepalive.widget.SwipeBackLayout;

import java.text.SimpleDateFormat;
import java.util.Date;

/**
 * 自定义锁屏activity 使用时需在AndroidManifest中注册
 */
public class LockScreenActivity extends AppCompatActivity {

    private static final String TAG = "LockScreenActivity";

    private TextView mTvLockDate;
    private ShimmerTextView mShimmer;
    private SwipeBackLayout mSwipeBack;

    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
                WindowManager.LayoutParams.FLAG_FULLSCREEN);
        setContentView(R.layout.activity_lock_screen);

        getWindow().addFlags(WindowManager.LayoutParams.FLAG_DISMISS_KEYGUARD);
        getWindow().addFlags(WindowManager.LayoutParams.FLAG_SHOW_WHEN_LOCKED);

        mShimmer = findViewById(R.id.shimmer);
        mTvLockDate = findViewById(R.id.lock_date);
        mSwipeBack = findViewById(R.id.swipeback);
        mSwipeBack.setSwipeBackListener(new SwipeBackLayout.SwipeBackFinishActivityListener(this));
        mTvLockDate.setText(getCurrentTime("yyyy-MM-dd"));
    }

    @Override
    protected void onStop() {
        super.onStop();
    }

    @Override
    protected void onDestroy() {
        super.onDestroy();
    }

    @Override
    public boolean onKeyDown(int keyCode, KeyEvent event) {
        int key = event.getKeyCode();
        switch (key) {
            case KeyEvent.KEYCODE_BACK: {
                return true;
            }
            case KeyEvent.KEYCODE_MENU: {
                return true;
            }
            default:
                break;
        }
        return super.onKeyDown(keyCode, event);
    }

    private String getCurrentTime(String format) {
        Date date = new Date();
        SimpleDateFormat dateFormat = new SimpleDateFormat(format);
        return dateFormat.format(date);
    }

}
